<?php
/**
 * Created by PhpStorm.
 * User: lance
 * Date: 11/29/17
 * Time: 2:22 PM
 */

namespace app\index\controller;

use think\Db;

class Todo extends Home
{

    /**
     * 向客户经理发送客户贷款提醒通知
     */
    function first()
    {
        $a_where = [
            'time' => strtotime(date('Y-m-d')),
            'status' => 0
        ];
        $a_time = Db::name('customer_loantime')->where($a_where)->select();
        foreach ($a_time as $a_item):
            //进行通知
            $a_customer = Db::name('customer')->where('id', $a_item['customer_id'])->find();
            $i_managerId = $a_customer['manager_id'];
            $a_loan = Db::name('customer_loan')->where('id', $a_item['loan_id'])->find();
            $s_time = date('Y-m-d H:i:s', Db::name('customer_loan')->where('id', $a_item['loan_id'])->value('time'));
            $s_tips = <<<EOT
<h3>客户$a_customer[name]贷款提醒</h3><br/>
<b>贷款借据号：</b>$a_loan[number]<br/>
<b>贷款金额：</b>$a_loan[money]<br/>
<b>贷款时间：</b>$s_time<br/>
<b>联系电话：</b>.$a_customer[tel1]
EOT;

            $a_data = [
                'type' => 3,
                'send_id' => 0,
                'manager_id' => $i_managerId,
                'title' => '客户贷款到期提醒',
                'content' => $s_tips,
                'time' => time(),
                'status' => 0
            ];
            Db::name('event_log')->insert($a_data);
            //更新通知状态
            Db::name('customer_loantime')->where('id', $a_item['id'])->update(['status' => 1]);
        endforeach;
    }

    /**
     * 向客户经理发送客户生日提醒信息
     */
    function two()
    {
        $s_time = date('m-d');
        $a_customers = Db::name('customer')->where('birthday', 'like', '%' . $s_time)->select();
        foreach ($a_customers as $key => $value):
            if (!empty($value['manager_id'])):
                $s_tips =  <<<EOT
<h3>客户$value[name]生日提醒</h3><br/>
<b>职业：</b>$value[career]<br/>
<b>性别：</b>$value[sex]<br/>
<b>生日：</b>$value[birthday]<br/>
<b>联系电话：</b>$value[tel1] $value[tel2]<br/>
EOT;
                //发送信息
                $a_data = [
                    'type' => 2,
                    'send_id' => 0,
                    'manager_id' => $value['manager_id'],
                    'title' => '客户生日提醒',
                    'content' => $s_tips,
                    'time' => time(),
                    'status' => 0
                ];
                Db::name('event_log')->insert($a_data);
            endif;
        endforeach;


    }
}